<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit" :showHistoryBtn="true" :saveBtnText="saveBtnText">
		<om-autoform ref="autoform" :initConfigData="topConfigData" :initValue="initValue"></om-autoform>
		<view v-if="ms_title_title1 && workList_title1.length">
			<om-autoform-outer :title="ms_title_title1" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title1" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="true" @click="openWorkTitle1(index)">
							<view>{{ item.indexName }}</view>
							<view class="text-gray text-sm padding-bottom-xs padding-top-xs">
								{{ (item.lastPlanNum ? '周计划数：' + item.lastPlanNum + ' | ' : '') + '周执行数：' + item.lastExcuteNum }}
							</view>
							<view v-if="item.targetValueName" class="text-gray text-sm">{{ '年目标：' + item.targetValueName }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title2 && workList_title2.length">
			<om-autoform-outer :title="ms_title_title2" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title2" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="false">
							<view>{{ item.itemName + getTitle2One(item) }}</view>
							<view v-if="item.deliveryName" class="text-gray text-sm padding-bottom-xs padding-top-xs">{{ item.deliveryName }}</view>
							<view class="text-gray text-sm">{{ reportDateFunc(item) }}</view>
							<view v-if="item.remark" class="text-gray text-sm">{{ item.remark }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title3 && workList_title3.length">
			<om-autoform-outer :title="ms_title_title3" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title3" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="false">
							<view>{{ item.workName + (item.adjustTypeCode ? '[' + item.adjustTypeCode + ']' : '') }}</view>
							<view v-if="item.deliveryName" class="text-gray text-sm padding-bottom-xs padding-top-xs">{{ item.deliveryName }}</view>
							<view class="text-gray text-sm">{{ adjustDateFunc(item) }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title5 && workList_title5.length">
			<om-autoform-outer :title="ms_title_title5" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title5" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="false">
							<view>{{ formatterText(item.name) + formatterText(item.productCode) + (item.userName || '') }}</view>
							<view class="text-gray text-sm padding-bottom-xs padding-top-xs">
								{{ formatterText(item.std, '', ' | ') + formatterText(item.unit, '', ' | ') + formatterText(item.storageSum, '', ' | ') + (item.sourceName || '') }}
							</view>
							<view class="text-gray text-sm">{{ productDate(item) }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title9 && selfdata.lastRemark">
			<om-sub :title="ms_title_title9">
				<uni-list>
					<uni-list-item :showArrow="false">
						<view>{{selfdata.lastRemark}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <view>{{selfdata.lastRemark}}</view> -->
				<!-- <textarea :auto-height="true" class="om-textarea" v-model="selfdata.lastRemark" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-show="ms_title_title12">
			<om-sub :title="ms_title_title12" :required="getRequired('title12')">
				<uni-list>
					<uni-list-item @click="editRemark(ms_title_title12, 'remark2', selfdata.remark2)">
						<view>{{selfdata.remark2 || "请点击输入"}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <textarea :auto-height="true" :maxlength="-1" class="om-textarea" v-model="selfdata.remark2" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-show="ms_title_title11">
			<om-sub :title="ms_title_title11" :required="getRequired('title11')">
				<uni-list>
					<uni-list-item @click="editRemark(ms_title_title11, 'remark1', selfdata.remark1)">
						<view>{{selfdata.remark1 || "请点击输入"}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <textarea :auto-height="true" :maxlength="-1" class="om-textarea" v-model="selfdata.remark1" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-show="ms_title_title16">
			<om-sub :title="ms_title_title16" :required="getRequired('title16')">
				<uni-list>
					<uni-list-item @click="editRemark(ms_title_title16, 'remark3', selfdata.remark3)">
						<view>{{selfdata.remark3 || "请点击输入"}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <textarea :auto-height="true" :maxlength="-1" class="om-textarea" v-model="selfdata.remark3" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-show="ms_title_title15">
			<om-sub :title="ms_title_title15" :required="getRequired('title15')">
				<uni-list>
					<uni-list-item @click="editRemark(ms_title_title15, 'outing', selfdata.outing)">
						<view>{{selfdata.outing || "请点击输入"}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <textarea :auto-height="true" :maxlength="-1" class="om-textarea" v-model="selfdata.outing" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title6 && workList_title6.length">
			<om-autoform-outer :title="ms_title_title6" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title6" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="true" @click="openWorkTitle6(index)">
							<view>{{ formatterText(item.tableCode, '订单号:', ' | ') + formatterText(item.instName, '', ' | ') + formatterText(item.userName, '业务负责人：') }}</view>
							<view class="text-gray text-sm padding-bottom-xs padding-top-xs">
								{{
									formatterText(item.customerCode, '顾客代码：', ' | ') + formatterText(item.tableUserName, '制单人：') 
								}}
							</view>
							<view class="text-gray text-sm">{{ ordersDate(item) +  ' | 可按期完工：' + (item.flag || '未配置') }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title8">
			<om-autoform-outer :title="ms_title_title8" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title8" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="true" @click="openWorkTitle8(index)" :showClear="true" @iconClear="delSubTitle8(index)">
							<view>{{ formatterText(item.indexName, '', ' | ') + item.orderNum }}</view>
							<view class="text-gray text-sm padding-bottom-xs padding-top-xs">
								{{ formatterText(item.targetValueName, '年目标：', ' | ') + formatterText(item.currentPlanNum, '周计划数：') }}
							</view>
						</uni-list-item>
					</view>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="openWorkTitle8()">{{ '增加' + ms_title_title8 }}</text>
				</view>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title4 && workList_title4.length">
			<om-autoform-outer :title="ms_title_title4" :collapse="true" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title4" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="false">
							<view>{{ item.workName3 }}</view>
							<view class="text-gray text-sm padding-bottom-xs padding-top-xs">{{ item.workOutput3 }}</view>
							<view class="text-gray text-sm">{{ formatterText(item.deliveryName3) + '计划' + item.planEnd3 + '完成' }}</view>
						</uni-list-item>
					</view>
				</uni-list>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view v-if="ms_title_title10">
		<!-- #endif -->
		<!-- #ifndef APP-PLUS -->
		<view v-show="ms_title_title10">
		<!-- #endif -->
			<om-autoform-outer :title="ms_title_title10" class="padding-0 margin-0">
				<uni-list>
					<view v-for="(item, index) in workList_title10" :key="index">
						<uni-list-item :avatar="index + 1" :showArrow="true" @click="openWorkTitle10(index)" :showClear="true" @iconClear="delSubTitle10(index)">
							<view>{{ item.workName}}</view>
							<view v-if="item.workOutput" class="text-gray text-sm padding-bottom-xs padding-top-xs">{{ item.workOutput }}</view>
							<view v-if="item.deliveryName" class="text-gray text-sm padding-bottom-xs padding-top-xs">{{ item.deliveryName }}</view>
							<view class="text-gray text-sm">{{ formatterText(item.dutyOffName, '负责人：', ' | ') + formatterText(item.evaOffName, '评价人：', ' | ') + '计划' + item.planEnd + '完成' }}</view>
						</uni-list-item>
					</view>
				</uni-list>
				<view class="tui-flex align-center justify-center padding-top">
					<text class="lg text-green cuIcon-add" @click="openWorkTitle10()">{{ '增加' + ms_title_title10 }}</text>
				</view>
			</om-autoform-outer>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view v-if="ms_title_title13">
		<!-- #endif -->
		<!-- #ifndef APP-PLUS -->
		<view v-show="ms_title_title13">
		<!-- #endif -->
			<om-sub :title="ms_title_title13" :required="getRequired('title13')">
				<uni-list>
					<uni-list-item @click="editRemark(ms_title_title13, 'remark', selfdata.remark)">
						<view>{{selfdata.remark || "请点击输入"}}</view>
					</uni-list-item>
				</uni-list>
				<!-- <textarea :auto-height="true" :maxlength="-1" class="om-textarea" v-model="selfdata.remark" placeholder="请输入" /> -->
			</om-sub>
			<om-white-space bgColor="#eee"></om-white-space>
		</view>
		<view v-if="ms_title_title14">
			<om-sub :title="ms_title_title14" :required="getRequired('title14')">
				<uni-list>
					<uni-list-item @click="selectUserFunc">
						<view >{{selfdata.formUserNames || "请选择"}}</view>
					</uni-list-item>
				</uni-list>
			</om-sub>
		</view>
	</om-addpage>
</template>

<script>
import { getUrl, confirmModal } from '@/static/js/common.js';
import { formValidation, tranferToEditors, changeEditor, configSelectData, hasValue } from '@/static/js/formUtil.js';
import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
export default {
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return {
			menuName: '',
			id: '',
			busCode: 'CMF0204',
			formdata: {},
			selfdata: {
				remark2: '',//上周指标或工作项未完成说明
				lastRemark: '',//上周计划工作要点
				remark1: '',//上周报告事项
				remark3: '',//上周项目完成情况报告
				outing: '',//上周出差行程
				remark: '',//本周工作要点
				formUserNames:"",//可阅读人员
				formUserIds:""
			},
			topConfigData: [],
			mainConfigData: {},
			subConfigData: {},
			initValue: {
				busCode: 'CMF0204',
				index1: '', //上周绩效指标执行情况
				product: '', //截止上周未按期完工入库的产品信息
				order: '', //本周需完工入库的订单信息
				index8: '', //本周绩效指标计划
				work: '' //临时工作计划
			},
			workitemCacheKey: 'obj-w-report-workitem-cache',
			workConfigDataCacheKey: 'obj-w-report-work-configdata-cache',
			workTitle1CacheKey: 'obj-w-report-work-title1-cache',
			workTitle6CacheKey: 'obj-w-report-work-title6-cache',
			workTitle8CacheKey: 'obj-w-report-work-title7-cache',
			workTitle10CacheKey: 'obj-w-report-work-title10-cache',
			workList_title1: [], //上周绩效指标执行情况
			ms_title_title1: '',
			workList_title2: [], //上周重点工作项完成情况
			ms_title_title2: '',
			workList_title3: [], //上周重点工作调整情况
			ms_title_title3: '',
			workList_title5: [], //截止上周未按期完工入库的产品信息
			ms_title_title5: '',
			workList_title6: [], //本周需完工入库的订单信息
			ms_title_title6: '',
			workList_title8: [], //本周绩效指标计划
			ms_title_title8: '',
			workList_title4: [], //本周重点工作项计划
			ms_title_title4: '',
			ms_title_title9: '', //上周计划工作要点
			ms_title_title12: '', //上周指标或工作项未完成说明
			ms_title_title11: '', //上周报告事项
			ms_title_title16: '', //上周项目完成情况报告
			ms_title_title15: '', //上周出差行程
			workList_title10: [], //本周临时工作计划
			ms_title_title10: '',
			ms_title_title13: '',//本周工作要点
			ms_title_title14: '',//可阅读人员
			yearWeekData: [],
			userCacheKey:"obj-w-weekreport-user-cache",
			selectUsers:[],
			scoreCode:"DD021017003",
			saveBtnText:""
		};
	},
	computed: {
		...mapState(useLoginUserStore, ['userName', 'userId'])
	},
	watch: {
		workList_title1: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.index1 = JSON.stringify(newValue);
				} else {
					this.initValue.index1 = JSON.stringify(newValue);
				}
			} else {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.index1 = '';
				} else {
					this.initValue.index1 = '';
				}
			}
		},
		workList_title5: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.product = JSON.stringify(newValue);
				} else {
					this.initValue.product = JSON.stringify(newValue);
				}
			} else {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.product = '';
				} else {
					this.initValue.product = '';
				}
			}
		},
		workList_title6: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.order = JSON.stringify(newValue);
				} else {
					this.initValue.order = JSON.stringify(newValue);
				}
			} else {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.order = '';
				} else {
					this.initValue.order = '';
				}
			}
		},
		workList_title8: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.index8 = JSON.stringify(newValue);
				} else {
					this.initValue.index8 = JSON.stringify(newValue);
				}
			} else {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.index8 = '';
				} else {
					this.initValue.index8 = '';
				}
			}
		},
		workList_title10: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.work = JSON.stringify(newValue);
				} else {
					this.initValue.work = JSON.stringify(newValue);
				}
			} else {
				if (this.$refs.autoform) {
					this.$refs.autoform.formdata.work = '';
				} else {
					this.initValue.work = '';
				}
			}
		},
		selectUsers: function(newValue, oldValue) {
			if (newValue && newValue.length) {
				this.selfdata.formUserIds = newValue.map(e=>e.id).join(",")
				this.selfdata.formUserNames = newValue.map(e=>e.userPosInstName).join(",")
			}else{
				this.selfdata.formUserIds =""
				this.selfdata.formUserNames = ""
			}
		},
	},
	methods: {
		getTitle2One(item){
			var arr = []
			if(item.evaluateUserName){
				arr.push("评价人：" +item.evaluateUserName)
			}
			if(hasValue(item.score)){
				arr.push('得分：' + item.score)
			}
			if(hasValue(item.maxScore)){
				arr.push('总分：' + item.maxScore)
			}
			if(arr.length){
				return "["+arr.join(",")+"]"
			}else{
				return ""
			}
		},
		initSubData() {
			Object.assign(this, {
				workList_title1: [], //上周绩效指标执行情况
				ms_title_title1: '',
				workList_title2: [], //上周重点工作项完成情况
				ms_title_title2: '',
				workList_title3: [], //上周重点工作调整情况
				ms_title_title3: '',
				workList_title5: [], //截止上周未按期完工入库的产品信息
				ms_title_title5: '',
				workList_title6: [], //本周需完工入库的订单信息
				ms_title_title6: '',
				workList_title8: [], //本周绩效指标计划
				ms_title_title8: '',
				workList_title4: [], //本周重点工作项计划
				ms_title_title4: '',
				ms_title_title9: '', //上周计划工作要点
				ms_title_title12: '', //上周指标或工作项未完成说明
				ms_title_title11: '', //上周报告事项
				ms_title_title16: '', //上周项目完成情况报告
				ms_title_title15: '', //上周出差行程
				workList_title10: [], //本周临时工作计划
				ms_title_title10: '',
				ms_title_title13: '',
				ms_title_title14: '',//可阅读人员
				yearWeekData: [],
				selectUsers:[],
				saveBtnText:""
			})
		},
		getRequired(titleId) {
			var data = this.mainConfigData[titleId];
			if (data && data.length && data[0].editors && data[0].editors.length && data[0].editors[0].required) {
				return true;
			} else {
				return false;
			}
		},
		formatterText(item, prefix, suffix) {
			if (!prefix) {
				prefix = '';
			}
			if (!suffix) {
				suffix = '';
			}
			return item ? prefix + item + suffix : '';
		},
		formSubmit() {
			let _that = this
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				var formdata = {}
				Object.assign(formdata,_that.formdata,_that.selfdata)
				for(var i in _that.mainConfigData){
					checkRes = formValidation(_that.mainConfigData[i], formdata);
					if(checkRes){
						_that.om.toast(checkRes);
						return
					}
				}
				_that.om.formSave('tweekMeetingReport/addTweekMeetingReport', formdata, _that);
			}
		},
		dateFunc(item) {
			var s = '';
			if (item.planEndDate) {
				s += '计划' + item.planEndDate + '完成';
			}
			if (s) {
				s += ',';
			}
			if (item.actualEndDate) {
				s += '实际' + item.actualEndDate + '完成';
			} else {
				s += '实际完成时间未填写';
			}
			return s;
		},
		productDate(item) {
			var s = '';
			if (item.date) {
				s += '计划' + item.date + '发货';
			}
			if (s) {
				s += ',';
			}
			if (item.storageDate) {
				s += '实际' + item.storageDate + '入库';
			} else {
				s += '无实际入库日期';
			}
			return s;
		},
		ordersDate(item) {
			var s = '';
			if (item.tableDate) {
				s += item.tableDate + '制表';
			}
			if (item.date) {
				if (s) {
					s += ',';
				}
				s += '计划' + item.date + '发货';
			}
			return s;
		},
		openWorkTitle1(index) {
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				uni.setStorage({
					key: this.workConfigDataCacheKey,
					data: this.subConfigData.title1
				});
				uni.setStorage({
					key: this.workTitle1CacheKey,
					data: this.workList_title1
				});
				var param = {
					configDataCacheKey: this.workConfigDataCacheKey,
					cachename: this.workTitle1CacheKey,
					index: index
				};
				var url = getUrl('data-info-title1', param);
				uni.navigateTo({
					url: url
				});
			}
		},
		openWorkTitle6(index) {
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				uni.setStorage({
					key: this.workConfigDataCacheKey,
					data: this.subConfigData.title6
				});
				uni.setStorage({
					key: this.workTitle6CacheKey,
					data: this.workList_title6
				});
				var param = {
					configDataCacheKey: this.workConfigDataCacheKey,
					cachename: this.workTitle6CacheKey,
					index: index
				};
				var url = getUrl('data-info-title6', param);
				uni.navigateTo({
					url: url
				});
			}
		},
		openWorkTitle8(index) {
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				uni.setStorage({
					key: this.workConfigDataCacheKey,
					data: this.subConfigData.title8
				});
				uni.setStorage({
					key: this.workTitle8CacheKey,
					data: this.workList_title8
				});
				var param = {
					configDataCacheKey: this.workConfigDataCacheKey,
					cachename: this.workTitle8CacheKey,
					index: index,
					zposId: this.formdata.zposId,
					year: this.formdata.year,
					week: this.formdata.week
				};
				var url = getUrl('data-info-title8', param);
				uni.navigateTo({
					url: url
				});
			}
		},
		delSubTitle8(index) {
			if (index != null) {
				this.workList_title8.splice(index, 1);
			}
		},
		openWorkTitle10(index) {
			var checkRes = formValidation(this.$refs.autoform.configData, this.formdata);
			if (checkRes) {
				this.om.toast(checkRes);
			} else {
				uni.setStorage({
					key: this.workConfigDataCacheKey,
					data: this.subConfigData.title10
				});
				uni.setStorage({
					key: this.workTitle10CacheKey,
					data: this.workList_title10
				});
				var param = {
					configDataCacheKey: this.workConfigDataCacheKey,
					cachename: this.workTitle10CacheKey,
					index: index
				};
				var url = getUrl('data-info-title10', param);
				uni.navigateTo({
					url: url
				});
			}
		},
		delSubTitle10(index) {
			if (index != null) {
				this.workList_title10.splice(index, 1);
			}
		},
		reportDateFunc(item) {
			var s = '';
			if (item.planEndDate) {
				s += '计划' + item.planEndDate + '完成';
			}
			if (s) {
				s += ',';
			}
			if (item.actualEndDate) {
				s += '实际' + item.actualEndDate + '完成';
			} else {
				s += '实际完成时间未填写';
			}
			return s;
		},
		adjustDateFunc(item) {
			var s = '';
			if (item.origPlanEnd) {
				s += '原计划' + item.origPlanEnd + '完成';
			}
			if (s) {
				s += ',';
			}
			if (item.adjustPlanEnd) {
				s += '调整后' + item.adjustPlanEnd + '完成';
			}
			return s;
		},
		//制表岗位选择后执行
		onSelectZpos(item) {
			let _that = this;
			this.om
				.request('posBusiAuth/GW165', {
					posId: item.id,
					code: _that.busCode
				})
				.then(res => {
					if (res.succeed) {
						if (res.value.tip) {
							errorModal(_that, '提示信息', res.value.tip, function() {
								_that.clearZpos();
							});
						} else {
							_that.loadYear();
							// _that.loadTitles(item.id);
						}
					} else {
						_that.om.toast(res[0].msg);
					}
				});
		},
		loadTitles(zposId, week) {
			let _that = this;
			var pro1 = this.om.request('formFieldConfig/addPage', {
				code: this.busCode,
				zposId: zposId
			}, "get", true);
			var pro2 = this.om.request('dictZero/getListByCode', {
				code: '36924'
			}, "get", true);
			var pro3 = this.om.request('dataDict/getIntByCode',{code:_that.scoreCode}, "get", true)
			uni.showLoading()
			Promise.all([pro1, pro2, pro3]).then(res => {
				uni.hideLoading()
				if (res[0].succeed) {
					let data = res[0].value;
					if (data.bodyTitle.length > 0) {
						for (var i = 0; i < data.bodyTitle.length; i++) {
							var title = ""
							if(~data.bodyTitle[i].itemName.indexOf("上周")) {
								title = _that._.replace(data.bodyTitle[i].itemName, "上周", week + "周")
							} else {
								title = _that._.replace(data.bodyTitle[i].itemName, "本周", (week+1) + "周")
							}
							_that['ms_title_' + data.bodyTitle[i].fieldId] = title;
							var datas = data['body' + i];
							if (data.bodyTitle[i].issub) {
								_that.subConfigData[data.bodyTitle[i].fieldId] = [
									{
										title: title,
										key: data.bodyTitle[i].fieldId,
										issub: true,
										editors: tranferToEditors(datas)
									}
								];
							} else {
								_that.mainConfigData[data.bodyTitle[i].fieldId] = [
									{
										title: title,
										key: data.bodyTitle[i].fieldId,
										editors: tranferToEditors(datas)
									}
								];
							}
						}
						if (_that.subConfigData.title6) {
							changeEditor(_that.subConfigData.title6[0].editors, 'flag', 'data', configSelectData(res[1], 'dicname', 'dicname'));
						}
						if (_that.subConfigData.title10) {
							changeEditor((_that.subConfigData.title10)[0].editors, 'maxScore', 'defaultValue', res[2].value);
							changeEditor((_that.subConfigData.title10)[0].editors, 'maxScore', 'max', res[2].value);
							changeEditor((_that.subConfigData.title10)[0].editors, 'maxScore', 'prompt', "介于1~"+res[2].value+"之间");
						}
						_that.saveBtnText="保存"
					}
					_that.ms_title_title14 = "抄送人"
				} else {
					_that.om.toast(res[0].msg);
				}
			});
		},
		loadYear() {
			let _that = this;
			this.om
				.request('tweekMeetingReport/getYearWeekList', {
					zposId: this.formdata.zposId
				})
				.then(res => {
					if (res.succeed) {
						if (res.value) {
							if (res.value.list && res.value.list.length > 0) {
								_that.yearFunc(res.value.list);
							}
						} else if (res.value.tip) {
							errorModal(_that, '提示信息', res.value.tip, function() {
								_that.clearZpos();
							});
						}
					} else {
						_that.om.toast(res[0].msg);
					}
				});
		},
		yearFunc(datas) {
			var arr = [];
			if (datas.length > 1 && datas[0].year === datas[1].year) {
				arr.push(datas[0]);
			} else {
				arr = datas;
			}
			this.yearWeekData = datas;
			this.$refs.autoform.changeEditor('topinfo', 'year', 'data', configSelectData(arr, 'year', 'year'));
		},
		clearZpos() {
			this.$refs.autoform.clear('topinfo', 'zposId');
			this.$refs.autoform.clear('topinfo', 'year');
			this.$refs.autoform.clear('topinfo', 'week');
			this.$refs.autoform.clear('topinfo', 'weekRange');
			this.initSubData();
		},
		onSelectYear() {
			if (this.yearWeekData.length) this.$refs.autoform.changeEditor('topinfo', 'week', 'data', configSelectData(this.yearWeekData, 'week', 'week'));
		},
		clearYear(){
			this.$refs.autoform.clear('topinfo', 'year');
			this.$refs.autoform.clear('topinfo', 'week');
			this.$refs.autoform.clear('topinfo', 'weekRange');
			this.initSubData();
		},
		onSelectWeek(item) {
			if(item && item.week){
				let _that = this;
				_that.loadTitles(_that.formdata.zposId, item.week);
				this.om.request(
					'tweekMeetingReport/getDatas',
					{
						zposId: _that.formdata.zposId,
						year: _that.formdata.year,
						week: item.week
					},
					'post'
				)
				.then(data => {
					if (data.succeed && data.value) {
						for(var i in data.value){
							//if(data.value[i] instanceof Array){
							if(Object.prototype.toString.call(data.value[i])==='[object Array]'){
								_that["workList_" + i] = data.value[i];
							}else if(typeof(data.value[i]) == "string"){
								if(i == "weekRange"){
									_that.$refs.autoform.formdata.weekRange = data.value[i]
								} else {
									_that.selfdata[i] = data.value[i];
								}
							}
						}
						if(!data.value.hasOwnProperty("title8")){
							_that.ms_title_title8 = ""
						}
					}
				});
			}
		},
		editRemark(title, valueField, defaultValue){
			var url = getUrl('/pages/public/editRemark/editRemark',{
				parentfieldname:"selfdata",
				fieldname: valueField,
				title: title,
				remark:defaultValue
			})
			uni.navigateTo({
				url:url
			})
		},
		clearWeek(){
			this.$refs.autoform.clear('topinfo', 'week');
			this.$refs.autoform.clear('topinfo', 'weekRange');
			this.initSubData();
		},
		selectUserFunc(){
			uni.setStorage({
				key:this.userCacheKey,
				data:this.selectUsers
			})
			var url = getUrl("../../public/multiSearch/multiSearch",{
				valuefield:"id",
				namefield:"userPosInstName",
				searchfield:"q",
				// initload:true,
				url:"temployee/getAutoCombobox",
				cachename:this.userCacheKey,
				placeholder:"请输入姓名"
			})
			uni.navigateTo({
				url:url
			})
		},
		delSub(index) {
			if (index != null) {
				this.workList.splice(index, 1);
			}
		},
		initLoad() {
			let _that = this;
			if (!this.busCode) {
				return;
			}
			var pro1 = this.om.request('formFieldConfig/addPage', { code: this.busCode });
			var pro2 = this.om.request('wxPosBusiAuth/isnewList', { code: this.busCode }, 'post');
			//多个AJAX同时完成时开始执行
			Promise.all([pro1, pro2])
				.then(res => {
					if (res[0].succeed) {
						let data = res[0].value;
						var topConfigData = [
							{
								key: 'topinfo',
								editors: tranferToEditors(data.top)
							}
						];
						changeEditor(topConfigData[0].editors, 'zposId', 'data', configSelectData(res[1], 'id', 'posname'));
						//赋值
						_that.$refs.autoform.configData = topConfigData;
					} else {
						_that.om.toast(res[0].msg);
					}
				})
				.catch(err => {
					console.log(err);
				});
		}
	},
	onLoad(options) {
		let _that = this;
		_that.menuName = options.title || '工作完成评价';
		uni.setNavigationBarTitle({
			title: _that.menuName
		});
		_that.busCode = options.code;
		_that.formdata.userId = this.userId;
		uni.removeStorage({
			key: _that.workTitle1CacheKey
		});
		uni.removeStorage({
			key: _that.workTitle6CacheKey
		});
		uni.removeStorage({
			key: _that.workTitle8CacheKey
		});
		uni.removeStorage({
			key: _that.workTitle10CacheKey
		});
		uni.removeStorage({
			key: _that.userCacheKey
		});
		_that.initLoad();
	},
	onShow() {
		let _that = this;
		if (_that.$refs.autoform) {
			uni.getStorage({
				key: _that.workTitle1CacheKey,
				success: function(res) {
					_that.workList_title1 = res.data;
					uni.removeStorage({
						key: _that.workTitle1CacheKey
					});
				}
			});
			uni.getStorage({
				key: _that.workTitle6CacheKey,
				success: function(res) {
					_that.workList_title6 = res.data;
					uni.removeStorage({
						key: _that.workTitle6CacheKey
					});
				}
			});
			uni.getStorage({
				key: _that.workTitle8CacheKey,
				success: function(res) {
					_that.workList_title8 = res.data;
					uni.removeStorage({
						key: _that.workTitle8CacheKey
					});
				}
			});
			uni.getStorage({
				key: _that.workTitle10CacheKey,
				success: function(res) {
					_that.workList_title10 = res.data;
					uni.removeStorage({
						key: _that.workTitle10CacheKey
					});
				}
			});
			uni.getStorage({
				key: _that.userCacheKey,
				success: function(res) {
					_that.selectUsers = res.data;
					uni.removeStorage({
						key: _that.userCacheKey
					});
				}
			});
		}
	}
};
</script>
<style></style>
